require('./env.js')
require('./origin.js')
const CryptoJS = require('crypto-js');

function sha256(e) {
    return CryptoJS.SHA256(e).toString();
}
// var dd='1|8|sha256|2025-08-14T18:17:19.793202+08:00|54088bb07d2df3c46b79f80300b0abbe|e3f74ec54be64052b44c963b8fea9ea6||3478bfcc750b6bf6';
// console.log(sha256(dd));
// 生成随机字符串
function generateRd() {
    let rd = '';
    for (let i = 0; i < 4; i++) {
        rd += (65536 * (1 + Math.random()) | 0).toString(16).substring(1);
    }
    return rd;
}
// var _ᕾᖆᕶᖚ = window._ᖃᕿᕾᖉ.$_Co

// 主函数：直接生成最终的w值
// function generateW(dist,dtime, captchid, lot_number) {
//     // 生成随机字符串
//     const rd = generateRd();
//
//     // 构建pow_msg
//     const pow_msg = `1|8|sha256|${dtime}|${captchid}|${lot_number}||${rd}`;
//
//     // 构建参数对象
//     const params = {
//         "setLeft": dist,
//         "passtime": 672,
//         "userresponse": dist / 1.0059466666666665 + 2,
//         "device_id": "",
//         "lot_number": lot_number,
//         "pow_msg": pow_msg,
//         "pow_sign": sha256(pow_msg),
//         "geetest": "captcha",
//         "lang": "zh",
//         "ep": "123",
//         "biht": "1426265548",
//         "gee_guard": {
//             "roe": {
//                 "aup": "3", "sep": "3", "egp": "3", "auh": "3",
//                 "rew": "3", "snh": "3", "res": "3", "cdc": "3"
//             }
//         },
//         "YUHD": "yaNq",
//         "ec69806a": {
//             "4ec8df66": {
//                 "662f": "ec8d"
//             }
//         },
//         "em": {
//             "ph": 0, "cp": 0, "ek": "11", "wd": 1,
//             "nt": 0, "si": 0, "sc": 0
//         }
//     };
//
//     // 转换为JSON字符串
//     const pp = JSON.stringify(params);
//
//     // 加密pp得到u
//     const u = window._u.encrypt(pp, rd);
//
//     // 加密rd得到_
//     const _ = new window._ᖄᖙᕶᕵ().encrypt(rd);
//
//     // 生成最终的w
//     const w = window.atohex(u) + _;
//
//     return w;
// }
// tttt='{"setLeft":187,"passtime":1439,"userresponse":187.8945470932853,"device_id":"","lot_number":"e3f74ec54be64052b44c963b8fea9ea6","pow_msg":"1|8|sha256|2025-08-14T18:17:19.793202+08:00|54088bb07d2df3c46b79f80300b0abbe|e3f74ec54be64052b44c963b8fea9ea6||3478bfcc750b6bf6","pow_sign":"00c9ec5a333ee5578c998b0bc5c2979613c15c7c2b23b477d9405432d30dbbfb","geetest":"captcha","lang":"zh","ep":"123","biht":"1426265548","gee_guard":{"roe":{"aup":"3","sep":"3","egp":"3","auh":"3","rew":"3","snh":"3","res":"3","cdc":"3"}},"YUHD":"yaNq","f74ec54b":{"963b8fea":{"449f":"63b8"}},"em":{"ph":0,"cp":0,"ek":"11","wd":1,"nt":0,"si":0,"sc":0}}'
// 使用示例
// const w = generateW("1", "8", "sha256", 102, "5e143f521b6a45e08be531e651e7e211", "2025-08-14T11:29:28.917609+08:00", "54088bb07d2df3c46b79f80300b0abbe");
// console.log(w);
// // console.log(window._ᖃᕿᕾᖉ)
// // console.log(_ᕾᖆᕶᖚ(39))
// console.log(_ᕾᖆᕶᖚ(55))
// var _ᕸᕾᕿᖙ = {
//     "(n[2:9])+.+(n[20:27])+.+(n[4]+n[8]+n[28]+n[25])": "n[21:24]"
// }

// console.log(window[_ᕾᖆᕶᖚ(10)][_ᕾᖆᕶᖚ(54)])
// var i = (0, _ᕿᕷᕵᕾ['getStringByIndexes'])(_ᖉᖘᕺᖙ['lot'], _ᖉᖘᕺᖙ['lotNumber']);
// var r = (0, _ᕿᕷᕵᕾ['getStringByIndexes'])(_ᖉᖘᕺᖙ['lotRes'], _ᖉᖘᕺᖙ['lotNumber']);
// console.log(i)
// console.log(r)
// console.log(window.getStringByIndexes.exports.getStringByIndexes)
function generateW(dist, dtime, captchid, lot_number) {
    // 生成随机字符串
    const rd = generateRd();

    // 构建pow_msg
    const pow_msg = `1|8|sha256|${dtime}|${captchid}|${lot_number}||${rd}`;

    // 从lot_number生成动态键
    const key1 = lot_number.substring(0, 8);
    const key2 = lot_number.substring(12, 20);
    const key3 = lot_number.substring(20, 24);

    // 直接用字符串模板构建JSON
    // const pp = `{"setLeft":${dist},"passtime":1439,"userresponse":${dist / 1.0059466666666665 + 2},"device_id":"","lot_number":"${lot_number}","pow_msg":"${pow_msg}","pow_sign":"${sha256(pow_msg)}","geetest":"captcha","lang":"zh","ep":"123","biht":"1426265548","gee_guard":{"roe":{"aup":"3","sep":"3","egp":"3","auh":"3","rew":"3","snh":"3","res":"3","cdc":"3"}},"YUHD":"yaNq","${key1}":{"${key2}":{"449f":"${key3}"}},"em":{"ph":0,"cp":0,"ek":"11","wd":1,"nt":0,"si":0,"sc":0}}`;
    const pp = `{"setLeft":${dist},"passtime":1439,"userresponse":${dist / 1.0059466666666665 + 2},"device_id":"","lot_number":"${lot_number}","pow_msg":"${pow_msg}","pow_sign":"${sha256(pow_msg)}","geetest":"captcha","lang":"zh","ep":"123","biht":"1426265548","gee_guard":{"roe":{"aup":"3","sep":"3","egp":"3","auh":"3","rew":"3","snh":"3","res":"3","cdc":"3"}},"YUHD":"yaNq","f74ec54b":{"963b8fea":{"449f":"63b8"}},"em":{"ph":0,"cp":0,"ek":"11","wd":1,"nt":0,"si":0,"sc":0}}`;

    // 加密pp得到u
    const u = window._u.encrypt(pp, rd);

    // 加密rd得到_
    const _ = new window._ᖄᖙᕶᕵ().encrypt(rd);

    // 生成最终的w
    const w = window.atohex(u) + _;

    return w;
}